#!/bin/bash

set -o errexit
set -o xtrace

test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions

create_namespace $namespace
deploy_operator

kubectl_bin apply -f $conf_dir/secrets.yml -f $conf_dir/client.yml -f $conf_dir/minio-secret.yml
cluster="liveness"

desc 'create first PSMDB cluster'
spinup_psmdb ${cluster}-rs0 $test_dir/conf/${cluster}-rs0.yml
compare_kubectl "statefulset/${cluster}-rs0"

desc 'change liveness config'
postfix="-changed"
apply_cluster $test_dir/conf/${cluster}-rs0$postfix.yml
sleep 20
wait_for_running "${cluster}-rs0" "3"
compare_kubectl "statefulset/${cluster}-rs0" $postfix
destroy $namespace
